import { mapGetters } from 'vuex'

export default {
  computed: {
    ...mapGetters('cart', ['total']),
  },

  watch: {
    total: {
      immediate: true,
      handler(newVal) {
        // console.log('侦听器触发了', newVal)
        if (newVal > 0) {
          // console.log('我要开始设置角标了', newVal)
          uni.setTabBarBadge({
            index: 2,
            text: '' + newVal,
          })
        } else {
          uni.removeTabBarBadge({
            index: 2,
          })
        }
      },
    },
  },
  
  // this.$store.state.cart.cartItems
  // this.$store.getters['模块名/属性名']
  onShow() {
    uni.setTabBarBadge({
      index: 2,
      text: '' + this.$store.getters['cart/total'],
    })
  },

};